﻿namespace CookieTerm
{
    using System.Xml.Serialization;

    public class Bookmark
    {
        internal BookmarkManager Manager;
        private DisplaySettings displaySettings;
        private TerminalSettings terminalSettings;
        private string displaySettingsName;

        public Bookmark()
        {
        }

        public Bookmark(BookmarkManager manager)
        {
            this.Manager = manager;
        }

        public string Name { get; set; }

        public string Hostname { get; set; }

        public int Port { get; set; }

        public string Protocol { get; set; }

        public string DisplaySettingsName
        {
            get
            {
                return this.displaySettingsName;
            }

            set
            {
                this.displaySettingsName = value;
                this.displaySettings = null;
            }
        }

        public string TerminalSettingsName { get; set;}

        [XmlIgnore]
        public DisplaySettings DisplaySettings
        {
            get
            {
                if (this.displaySettings == null)
                {
                    this.displaySettings = this.Manager.FindDisplaySettings(DisplaySettingsName);
                    if (this.displaySettings == null)
                    {
                        this.displaySettings = DisplaySettings.Default;
                    }
                }

                return this.displaySettings;
            }

            set
            {
                this.displaySettings = value;
                this.displaySettingsName = this.displaySettings.Name;
            }
        }

        [XmlIgnore]
        public TerminalSettings TerminalSettings
        {
            get
            {
                if (this.terminalSettings == null)
                {
                    this.terminalSettings = this.Manager.FindTerminalSettings(TerminalSettingsName);
                    if (this.terminalSettings == null)
                    {
                        this.terminalSettings = TerminalSettings.Default;
                    }
                }

                return this.terminalSettings;
            }
        }
    }
}
